package priv.yiyuan.example.tomap;

import lombok.Data;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * Stream 使用，转Map
 *
 * @author YiYuan
 * @data 2025/8/19
 * @apoNote
 */
public class StreamToMap {

    @Data
    public static class Order {

        private String id;

        private String number;

        public Order(String id, String number) {
            this.id = id;
            this.number = number;
        }
    }

    /**
     * Function.identity()
     * <p>
     * 返回stream流元素本身
     *
     * @param orders
     */
    private void ListToMap(List<Order> orders) {

        Map<String, Order> idOrderMap = orders.stream()
                .collect(Collectors.toMap(Order::getId, Function.identity()));
    }
}
